package net.aaa.hotel.dao.impl;

import com.sun.xml.internal.ws.api.server.SDDocument;
import net.aaa.hotel.dao.PanDao;
import net.aaa.hotel.entity.PageInfo;
import net.aaa.hotel.util.BaseDB;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
@Repository
public class PanDaoImpl implements PanDao {
    @Override
    public List<Map> queryS(PageInfo pageInfo) {
        //String sql = "select ssId,ssName,ssCount as count from t_sheshi limit ?,?";
        String sql = "select ssId,ssName,ssCount as count from t_sheshi ";
        //return BaseDB.queryMap(sql,(pageInfo.getCurr()-1)*pageInfo.getNums(),pageInfo.getNums());
        return BaseDB.queryMap(sql);
    }

    @Override
    public int queryN() {
        String sql = "select count(*) a  from t_sheshi ";

        return Integer.parseInt(BaseDB.queryMap(sql).get(0).get("a") + "");
    }

    @Override
    public List<Map> queryP(PageInfo pageInfo) {
        String sql = "select * from t_pandian limit ?,?" ;
        return BaseDB.queryMap(sql,(pageInfo.getCurr()-1)*pageInfo.getNums(),pageInfo.getNums());
    }

    @Override
    public int queryPN() {
        String sql = "select count(*) a from t_pandian";
        return Integer.parseInt(BaseDB.queryMap(sql).get(0).get("a") + "");
    }

    @Override
    public int addPan(Map data) {
        String sql = "insert into t_pandian (pddate,pdra,pdrb)values(now(),?,?)";
        return BaseDB.insertGetKey(sql,data.get("pdra"),data.get("pdrb"));
    }

    @Override
    public int addPD(Map map, int i) {
        String sql = "insert into t_pandiandetail (pdid,ssid,sjcount,count,comm)values(?,?,?,?,?)";
        return BaseDB.update(sql,i,map.get("ssId"),map.get("ssCount"),map.get("count"),map.get("comm"));
    }

    @Override
    public int addPS(Map map) {
        String sql = "update t_sheshi set ssCount=? where ssId=?";
        return BaseDB.update(sql,map.get("ssCount"),map.get("ssId"));
    }

    @Override
    public List<Map> queryId(Integer integer) {
        String sql = "SELECT tp.*,ts.ssName from t_pandiandetail tp,t_sheshi ts WHERE tp.ssid=ts.ssId AND tp.pdid=?";

        return BaseDB.queryMap(sql,integer);
    }
}
